package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.SingerRoot;

import java.util.ArrayList;

import de.hdodenhof.circleimageview.CircleImageView;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/22.
 */
public class SingerAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<SingerRoot.DataEntity> dataEntityArrayList;


    public SingerAdapter(Context c, ArrayList<SingerRoot.DataEntity> dataEntityArrayList) {
        this.context = c;
        this.dataEntityArrayList = dataEntityArrayList;
    }

    @Override
    public int getCount() {
        return dataEntityArrayList != null && dataEntityArrayList.size() > 0 ? dataEntityArrayList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return dataEntityArrayList != null && dataEntityArrayList.size() > 0 ? dataEntityArrayList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.singer_item, null);
            holder = new ViewHolder();
            holder.singer_head = (CircleImageView) convertView.findViewById(R.id.singer_head);
            holder.singer_name = (TextView) convertView.findViewById(R.id.singer_name);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.singer_name.setText(dataEntityArrayList.get(position % dataEntityArrayList.size()).getSinger_name());
        Picasso.with(context).load(dataEntityArrayList.get(position % dataEntityArrayList.size()).getPic_url()).into(holder.singer_head);

        return convertView;
    }

    public  class ViewHolder {
        private CircleImageView singer_head;
        private TextView singer_name;
    }
}
